import {getComponent} from "@/utils/routerUtil";
import DialogView from "@/layouts/DialogView";
import { Util } from "@lowcode/jpaas-common-lib"
export default {
    methods:{
        //在弹窗中打开菜单
        openPopWin(item) {
            let data = {};
            if (item.settingType == 'iframe') {
                data.url = item.params;
            } else {
                data.menu = item;
                data.currentView = getComponent(item);
            }
            let conf = {
                component: DialogView,
                curVm: this,
                max: true,
                title: this.$i18(item.title),
                data: data
            };
            Util.open(conf);
        },
        //在新窗口打开菜单
        openNewWin(item) {
            //大屏新窗口
            if(item.settingType=="screen"){
                let params=JSON.parse(item.params);
                let url=location.protocol +"//" + location.host+params.url+"/preview/"+params.alias
                window.open(url, '_blank');
                return;
            }
            let path = process.env.VUE_APP_ADMIN_FRONT;
            let aryMenuPath = this.getMenuPath(item.id);
            let url = path;
            for (let i = 0; i < aryMenuPath.length; i++) {
                url += "/" + aryMenuPath[i].menuKey;
                if (i == 0) {
                    url += "/home";
                }
            }
            url=location.protocol +"//" + location.host +url.replace("//","/");
            //如果菜单参数为外网地址，则直接取该地址  2022-1-25
            let params=item.params;
            if(params){
                if(params.startWith('http://') || params.startWith('https://')){
                    url=params;
                }
            }
            window.open(url, '_blank');
        },
        openFuns(item, name) {
            let menuId = item.id;
            let pathParams = {name: name};
        //    this.generatePath(menuId);
            pathParams.params = {}
            if (item.params) {
                pathParams.params = JSON.parse(item.params);
            }
            pathParams.params.menuId = menuId;
            this.$router.push(pathParams);
        }
    }
}